package com.business.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.business.common.annotation.Log;
import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.enums.BusinessType;
import com.business.exam.domain.ExamQbName;
import com.business.exam.service.IExamQbNameService;
import com.business.common.utils.poi.ExcelUtil;
import com.business.common.core.page.TableDataInfo;

/**
 * 题库名称Controller
 *
 * @author zhanglele
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/questionbank/name")
public class ExamQbNameController extends BaseController
{
    @Autowired
    private IExamQbNameService examQbNameService;

    /**
     * 查询题库名称列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:name:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamQbName examQbName)
    {
        startPage();
        List<ExamQbName> list = examQbNameService.selectExamQbNameList(examQbName);
        return getDataTable(list);
    }

    /**
     * 导出题库名称列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:name:export')")
    @Log(title = "题库名称", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQbName examQbName)
    {
        List<ExamQbName> list = examQbNameService.selectExamQbNameList(examQbName);
        ExcelUtil<ExamQbName> util = new ExcelUtil<ExamQbName>(ExamQbName.class);
        util.exportExcel(response, list, "题库名称数据");
    }

    /**
     * 获取题库名称详细信息
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:name:query')")
    @GetMapping(value = "/{qbNameId}")
    public AjaxResult getInfo(@PathVariable("qbNameId") Long qbNameId)
    {
        return success(examQbNameService.selectExamQbNameByQbNameId(qbNameId));
    }

    /**
     * 新增题库名称
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:name:add')")
    @Log(title = "题库名称", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQbName examQbName)
    {
        return toAjax(examQbNameService.insertExamQbName(examQbName));
    }

    /**
     * 修改题库名称
     */
   //@PreAuthorize("@ss.hasPermi('questionbank:name:edit')")
    @Log(title = "题库名称", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQbName examQbName)
    {
        return toAjax(examQbNameService.updateExamQbName(examQbName));
    }

    /**
     * 删除题库名称
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:name:remove')")
    @Log(title = "题库名称", businessType = BusinessType.DELETE)
	@DeleteMapping("/{qbNameIds}")
    public AjaxResult remove(@PathVariable Long[] qbNameIds)
    {
        return toAjax(examQbNameService.deleteExamQbNameByQbNameIds(qbNameIds));
    }
}
